﻿using System;
using System.Collections.Generic;
using BLL;
using Model;

public partial class PCBA_PCBUnion_PCBUnionAdd : System.Web.UI.Page
{
    PCBUnion pu;
    PCBA pcba;

    public PCBA_PCBUnion_PCBUnionAdd()
    {
        pu = new PCBUnion();
        pcba = new PCBA();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string pCBTypeID = this.TextBox1.Text.Trim();
        string pCBSN = this.TextBox2.Text.Trim();
        string pCBASN = this.TextBox3.Text.Trim();
        string pCBVendorWeek = this.TextBox4.Text.Trim();
        PCBAInfo pi1 = pcba.LoadEntity(pCBASN);
        if (pi1.PCBASN == pCBASN)
        {
            string str = "此PCBA成品序列号已经关联过PCB板，无法重复关联！";
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
        }
        else
        {  
            try
            {
                PCBAInfo pi = new PCBAInfo(pCBASN, pCBTypeID);
                pcba.Insert(pi);
                PCBUnionInfo pui = new PCBUnionInfo(pCBASN, pCBSN, pCBVendorWeek, DateTime.Now, User.Identity.Name);
                pu.Insert(pui);
                //this.TextBox2.Text = "";
                this.TextBox3.Text = "";
                this.TextBox3.Focus();
                string str = "录入成功！";
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
            }
            catch
            {
                string str = "出现错误，请联系相关人员！";
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
            }
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string pCBASN = this.TextBox5.Text.Trim();
        IList<PCBUnionInfo> list = new List<PCBUnionInfo>();
        PCBUnionInfo pui = pu.LoadEntity(pCBASN);
        list.Add(pui);
        this.GridView1.DataSource = list;
        this.GridView1.DataBind();
    }
}
